<?php
namespace app\admin\controller;

class ArticleSort extends Base
{
    public function table()
    {
        return $this->view->fetch();
    }

    public function tableHandle()
    {
        $rt = $this->logic()->articleSort()->getTables($this->params);
        return json_print($rt,'', $this->returnStyle);
    }

    public function add()
    {
        return $this->fetch();
    }

    public function addHandle()
    {
        $rt = $this->logic()->articleSort()->add($this->params);
        return json_print($rt);
    }

    public function edit()
    {
        return $this->fetch();
    }

    public function editHandle()
    {
        $rt = $this->logic()->articleSort()->edit($this->params);
        return json_print($rt);
    }

    public function deleteHandle()
    {
        $rt = $this->logic()->articleSort()->del($this->params);
        return json_print($rt);
    }

    public function getGradeTree()
    {
        $rt = $this->logic()->articleSort()->getGradeTree();
        return json_print($rt,'', $this->returnStyle);
    }


//    /**
//     * @param $data 所需数据
//     * @param int $pid 父id
//     * @param int $notId 排除的id
//     * @param array $tree 返回的tree
//     * @param int $depth 当前的深度
//     * @return array
//     */
//    public function getSortTree($data, $pid = 0, $notId = -1, &$tree = [], $depth = 0)
//    {
//        // edit 时要排除自身及其子集
//        foreach ($data as $item) {
//            if ($item['pid'] == $pid && $item['id'] != $notId) {
//                $item['name'] = str_repeat('|--',$depth).'['.$item['name'].']';
//                $tree[] = $item;
//                $this->getSortTree($data, $item['id'], $notId, $tree, ++$depth);
//            }
//        }
//        return $tree;
//    }
//
//    public function getCrumbs($data, $pid, &$tree = [])
//    {
//        foreach ($data as $item) {
//            if ($item['id'] == $pid) {
//                $tree[] = $item['name'];
//                $this->getCrumbs($data, $item['pid'],$tree);
//            }
//        }
//        return $tree;
//    }


}